84

Beginner’s Guide to Code Algorithms

84

STEP 3 continued

    If A <> “.” And A <> “..” Then

      If FSO.folderExists(Folder & A) Then

      FolderNameIndex =​ FolderNameIndex +​ 1

      ReDim Preserve FolderNames(FolderNameIndex)

      FolderNames(FolderNameIndex) =​ Folder & A & “\”

    End If

    j =​ j +​ 1

    Application.StatusBar =​ “ Preparing the computation: Number of rows “ & j & “

Time is “ & Now

    End If

    A =​ Dir$()

Loop

      ‘ Recursion

If FolderNameIndex > 0 Then

      For jj =​ 1 To FolderNameIndex

        Call GetFolderNames2(FolderNames(jj))

      Next

End If

Exit Sub

Application.StatusBar =​ “ Preparing the computation: Number of rows “ & j & “

Time is “ & Now

errorresume:

N =​ j

End Sub

STEP 4

Note here the clever use of the MOD function. The MOD function provides a

remainder. By checking for the remainder when the overall time is divided by 300,

we implement a checkpoint for the user every five minutes.

Sub TimeLimit()

Y =​ DateDiff(“s”, B, Now)

If Y Mod 300 > 295 Then

OverallTime =​ OverallTime +​ Y /​ 60

X =​ InputBox(“Already 5 more minutes passed” & “ a total of “ &

Round(OverallTime, 2) & “ minutes -​ do u want to continue? “)

If Left(X, 1) =​ “Y” Or Left(X, 1) =​ “y” Then

Else

    End

End If

End If

End Sub

STEP 5

Sub GetFolderNames(Folder)

Dim FolderNames() As String

Dim SubFolders As Variant

Dim FileItem As Object

Dim SourceFolder As Object

FolderNameIndex =​ 0

Set fs =​ CreateObject(“Scripting.FileSystemObject”)

Set SourceFolder =​ FSO.GetFolder(Folder)